package cn.shop.dys.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;

import java.util.List;

import cn.shop.dys.R;
import cn.shop.dys.bean.Category;
import cn.shop.dys.constant.CommonConstant;

/**
 * Created by liulu on 2016/4/19.
 */
public class Category1Adapter extends BaseAdapter {
    Context context;
    private List<Category> category;

    public Category1Adapter(Context context, List<Category> category) {
        this.context = context;
        this.category = category;
    }

    @Override
    public int getCount() {
        return category.isEmpty() ? 0 : category.size();
    }

    @Override
    public Category getItem(int position) {
        return category.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view;
        ViewHolder viewHolder;
        Category category = getItem(position);
        if (convertView == null) {
            viewHolder = new ViewHolder();
            view = convertView.inflate(context, R.layout.category1_item, null);
            viewHolder.productImage = (ImageView) view.findViewById(R.id.iv_marketimage);
            viewHolder.productName = (TextView) view.findViewById(R.id.tv_marketname);
           // viewHolder.productPrice = (TextView) view.findViewById(R.id.tv_price);
            view.setTag(viewHolder);
        } else {
            view = convertView;
            viewHolder = (ViewHolder) view.getTag();
        }
        String url = CommonConstant.HOST+category.getPic();
        Glide.with(context)
                .load(url)
                .fitCenter()
                .crossFade()
                .into(viewHolder.productImage);

        viewHolder.productName.setText(category.getName());
       // viewHolder.productPrice.setText(product.getMarketPrice()+"");

        return view;
    }
};
class ViewHolder {
    TextView productPrice;
    TextView productName;
    ImageView productImage;
}


